import type { MesStationCollect, MesStationCollectDetail, StationCollectInfo } from "@/pages/mes/collect/entity";
import apiClient from "../../apiClient";

export interface PageListReq {
  //条码
  sn?: string;
  //采集时间
  collectTime?: Date;
  //当前页码
  page: number;
  //每页数量
  pageSize: number;
}

export interface PageListRes {
  //总记录数
  total: number;
  //数据列表
  records: MesStationCollect[];
}

const pageList = (data: PageListReq): Promise<PageListRes> =>
  apiClient.post({
    url: "/mes/station/collect/pageList",
    data
});
const getInfo = (id: React.Key): Promise<MesStationCollect> =>
  apiClient.get({
    url: `/mes/station/collect/${id}`
});

const add = (data: MesStationCollect): Promise<MesStationCollect> =>
  apiClient.post({
    url: "/mes/station/collect",
    data
});

const update = (data: MesStationCollect): Promise<MesStationCollect> =>
  apiClient.put({
    url: "/mes/station/collect",
    data
});

const remove = (ids: React.Key[]): Promise<void> =>
  apiClient.delete({
    url: "/mes/station/collect",
    params: {
    ids: ids.join(",")
  }
});
const getDetails = (id: React.Key): Promise<MesStationCollectDetail[]> =>
  apiClient.post({
    url: "/mes/station/collect/detail/list",
    data: {
      collectId: id
    }
  });

//采集条码扫码
const scan = (data:StationCollectInfo): Promise<StationCollectInfo> =>
  apiClient.post({
    url: "/mes/station/collect/scan",
    data: data
  });  

export const mesStationCollectService = {
  pageList,
  getInfo,
  add,
  update,
  remove,
  getDetails,
  scan
};

export default mesStationCollectService;